package com.link.ppt.View;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.link.ppt.App.App;
import com.link.ppt.Base.BaseActivity;
import com.link.ppt.R;
import com.link.ppt.Utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by liucxu on 2018/1/31.
 */

public class PPTTitleKeywordActivity extends BaseActivity {


    @BindView(R.id.layout_back)
    LinearLayout back_layout;
    @BindView(R.id.tv_title)
    TextView tv_title;

    @BindView(R.id.edt_title)
    EditText edt_title;
    @BindView(R.id.edt_key_word)
    EditText edt_key_word;
    @BindView(R.id.edt_shares)
    EditText edt_shares;


    private boolean isSelectPhoto = false;
    private String pptUrl = "";
    private String[] photos;

    @Override
    public int getLayoutId() {
        return R.layout.activity_ppt_title_keyword;
    }

    @Override
    public void setupView() {
        ButterKnife.bind(this);
        tv_title.setText(getResources().getString(R.string.ppt_string_46));
        isSelectPhoto = getIntent().getBooleanExtra("isSelectPhoto", false);
        if (!isSelectPhoto) {
            pptUrl = getIntent().getStringExtra("pptUrl");
        } else {
            photos=getIntent().getStringArrayExtra("photos");
        }
    }

    @Override
    public void setupData() {

    }

    @OnClick({R.id.layout_back, R.id.tv_next_step})
    void doClicks(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.layout_back:
                App.GetInstance().finishActivity(this);
                break;
            case R.id.tv_next_step:
                if(doValidate()){
                    if(!isSelectPhoto){
                        Intent intent = new Intent(this,SelectPPTIndustry.class);
                        intent.putExtra("isSelectPhoto",isSelectPhoto);
                        intent.putExtra("pptTitle",edt_title.getText().toString());
                        intent.putExtra("pptKeyWord",edt_key_word.getEditableText().toString());
                        intent.putExtra("pptUrl",pptUrl);
                        intent.putExtra("shares",edt_shares.getText().toString());
                        startActivity(intent);
                    }
                    else{
                        Intent intent = new Intent(this,SelectPPTIndustry.class);
                        intent.putExtra("isSelectPhoto",isSelectPhoto);
                        intent.putExtra("pptTitle",edt_title.getText().toString());
                        intent.putExtra("pptKeyWord",edt_key_word.getEditableText().toString());
                        intent.putExtra("photos",photos);
                        intent.putExtra("shares",edt_shares.getText().toString());
                        startActivity(intent);
                    }
                }
                break;
        }
    }

    private boolean doValidate() {
        if (TextUtils.isEmpty(edt_title.getText().toString())) {
            ToastUtils.showShortToast(PPTTitleKeywordActivity.this,R.string.ppt_string_48);
            return false;
        }
        if (TextUtils.isEmpty(edt_key_word.getEditableText().toString())) {
            ToastUtils.showShortToast(PPTTitleKeywordActivity.this,R.string.ppt_string_51);
            return false;
        }
        return true;
    }
}
